package lc20240703;

public class DifferentPathII {
    public int uniquePathsWithObstacles(int[][] obstacleGrid) {
        //网格中的障碍物和空位置分别用 1 和 0 来表示。
        //下一步只能是i+1，或者j+1
        int count=0;
        int n=obstacleGrid.length;
        int m=obstacleGrid[0].length;
        int[] f=new int[m];

        f[0]=obstacleGrid[0][0]==0?1:0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (obstacleGrid[i][j]==1){
                    f[j]=0;
                    continue;
                }
                if (j-1>=0&&obstacleGrid[i][j-1]==0){
                    f[j]=f[j]+f[j-1];
                }
            }
        }
        return f[m-1];
    }
}
